How to check in javascript if in the string there are two "=" symbols and to throw a mistake (beacuse for example 1+=2=3 is wrong but 1+2=3 is right)
function validateText() {
const text = document.getElementById('text').value;
if ((text.match(/=/g)?.length || 0) < 2) {
document.getElementById('result').innerHTML = "Valid";
} else {
document.getElementById('result').innerHTML = "Invalid";
}
}
<textarea id="text"></textarea>
<button onclick=validateText()>Validate</button>
<p id="result"></p>
var input_true = '1 + = 2 + 3';
var input_false = '1 + = 2 + = 3';
var success = /^[^=]*=[^=]*$/.test(input_true); // pass
var not_success = /^[^=]*=[^=]*$/.test(input_false); // fails